import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;

public class VU extends Course implements FinalExamsInterface, ExcercicesInterface{
	private FinalExams finalExams;
	private Excercises excercices;
	
	public VU(String lvanr, String title, double ects, double workinghours, GregorianCalendar enrollStart, GregorianCalendar enrollEnd, GregorianCalendar checkOutEnd, Professor professor, boolean visible, int number, int maxStudents) {
		super(lvanr, title, ects, workinghours, enrollStart, enrollEnd, checkOutEnd, professor, visible);
		this.excercices = new Excercises(this, number, maxStudents);
	}
	
	public VU(String lvanr, String title, double ects, double workinghours, GregorianCalendar enrollStart, GregorianCalendar enrollEnd, GregorianCalendar checkOutEnd, Professor professor, boolean visible) {
		super(lvanr, title, ects, workinghours, enrollStart, enrollEnd, checkOutEnd, professor, visible);
		this.excercices = new Excercises();
	}

	public VU(String lvanr, String title, double ects, double workinghours, GregorianCalendar enrollStart, GregorianCalendar enrollEnd, GregorianCalendar checkOutEnd, Professor professor, int number, int maxStudents) {
		super(lvanr, title, ects, workinghours, enrollStart, enrollEnd, checkOutEnd, professor);
		this.excercices = new Excercises(this, number, maxStudents);
		
	}

	public VU(String lvanr, String title, double ects, double workinghours, GregorianCalendar enrollStart, GregorianCalendar enrollEnd, GregorianCalendar checkOutEnd, Professor professor) {
		super(lvanr, title, ects, workinghours, enrollStart, enrollEnd, checkOutEnd, professor);
		this.excercices = new Excercises();
	}
	
	@Override
	public Excercises getExcercices() {
		return excercices;
	}

	@Override
	public void giveCertificate(Student student) {
		int mark1 = this.excercices.finalMarks.get(student).getMark();
		HashMap<GregorianCalendar, FinalExam> studentExams = finalExams.getGraduates().get(student);
		GregorianCalendar lastDate = new GregorianCalendar(1970, 1-1, 1);
		Iterator it = studentExams.keySet().iterator();
		while(it.hasNext()) {
			GregorianCalendar key = (GregorianCalendar)it.next();
			if(key.after(lastDate)) {
				lastDate = key;
			}
		}
		int mark2 = studentExams.get(lastDate).getMark().getMark();
		Mark mark = Mark.createMark((mark1+mark2)/2);
		student.addCertificate(new Certificates(this, mark, this.getProfessor()));
	}

	@Override
	public FinalExams getFinalExams() {
		return finalExams;
	}
	
}
